#define DEBUG
#include <cstdio>
#include <cstdlib>
#include <ctime>

using namespace std;

int min(int a, int b) {
  return a<b ? a : b;
}

void makeData(int maxn, int maxm) {
  const int maxa=1000000000, c=500;
  FILE *f = fopen("median.in", "w");
  static int a[500001], b[500000+1];
  int n=rand()%maxn+1, m=rand()%maxm+1;
  fprintf(f, "%d %d\n", n, m);
  for (int i=1; i<=n; i++) {
    a[i] = rand()%min(maxa-a[i-1]+1, c)+a[i-1];
    fprintf(f, "%d ", a[i]);
  }
  fprintf(f, "\n");
  for (int i=1; i<=n; i++) {
    b[i] = rand()%min(maxa-b[i-1]+1, c)+b[i-1];
    fprintf(f, "%d ", b[i]);
  }
  fprintf(f, "\n");

  a[n+1] = b[n+1] = maxa;
  for (int i=1; i<=n; i++) {
    int opt=rand()%2+1;
    fprintf(f, "%d ", opt);
    if (opt==1) {
      int x, y, z;
      x=rand()%2, y=rand()%n+1;
      if (x) {
	b[y] = z = rand()%(b[y+1]-b[y-1]+1)+b[y-1];
      } else {
	a[y] = z = rand()%(a[y+1]-a[y-1]+1)+a[y-1];
      }
      fprintf(f, "%d %d %d\n",  x, y, z);
    } else {
      int l1, r1, l2, r2;
      l1=rand()%n+1, r1=rand()%(n-l1+1)+l1, l2=rand()%n+1, r2=rand()%(n-l2+1)+l2;
      fprintf(f, "%d %d %d %d\n", l1, r1, l2, r2);
    }
  }
  fclose(f);
}

int main() {
  int times, maxn, maxm;
  srand(time(0));
  printf("Times, Maxn, Maxm:");
  scanf("%d %d %d", &times, &maxn, &maxm);
  for (int i=1; i<=times; i++) {
    makeData(maxn, maxm);
    system("./1");
    system("./1_bf");
    if (system("cmp median.out median_bf.out")) {
      printf("WA\n");
      return -1;
    }
  }

  return 0;
}
